/**
 * Created by dinghh on 2018-7-11.
 */
angular.module('MetronicApp').controller('CaseAnalysisController',
    ['$rootScope', '$scope', '$state', '$uibModal', 'toastr','$location','$stateParams', 'FileStorageService', 'CaseAnalysisService',
        function ($rootScope, $scope, $state, $uibModal, toastr,$location,$stateParams, FileStorageService, CaseAnalysisService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;
            });

            $scope.condition = {};
            $scope.yearList = [];
            $scope.cityList = [];

            // 上面4个tab页切换
            $scope.tabItemList = [
                {
                    "name": "污染源分析",
                    "router": "sourceAnalysisList",
                    "selected": false
                },
                {
                    "name": "周期性分析",
                    "router": "periodicAnalysisList",
                    "selected": false
                },
                {
                    "name": "案例分析",
                    "router": "caseAnalysisList",
                    "selected": true
                },
                {
                    "name": "传输影响分析",
                    "router": "pollutantSourceList",
                    "selected": false
                }
            ];

            $("#caseAnalysis li").click(function (e) {
                //左边标签体系tab点击背景变色
                $(this).addClass('selected');
                $(this).siblings('li').removeClass('selected');
                e.preventDefault();
                var item = $(this).index();  //获取索引下标 也从0开始
                ("下标索引值为：" + item );
            });
            //给左边标签体系tab增加点击事件，切换li标签内容
            $scope.changeTab=function (index) {
                switch (index) {
                    case 0:
                        CaseAnalysisService.putSearchParams({
                            search: $scope.condition.search
                        });
                        CaseAnalysisService.getProcessCase().$promise.then(function (result) {
                            if("success" == result.status){
                                $scope.model = result.data;
                            }else {
                                for(var index in result.errors){
                                    toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                }
                            }
                        });
                        break;
                    case 1:
                        CaseAnalysisService.putSearchParams({
                            search: $scope.condition.search
                        });
                        CaseAnalysisService.getStabilityCase().$promise.then(function (result) {
                            if("success" == result.status){
                                $scope.model = result.data;
                            }else {
                                for(var index in result.errors){
                                    toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                }
                            }
                        });
                        break;
                    case 2:
                        CaseAnalysisService.putSearchParams({
                            search: $scope.condition.search
                        });
                        CaseAnalysisService.getLocalCase().$promise.then(function (result) {
                            if("success" == result.status){
                                $scope.model = result.data;
                            }else {
                                for(var index in result.errors){
                                    toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                }
                            }
                        });
                        break;
                    case 3:
                        CaseAnalysisService.putSearchParams({
                            search: $scope.condition.search
                        });
                        CaseAnalysisService.getForeignCase().$promise.then(function (result) {
                            if("success" == result.status){
                                $scope.model = result.data;
                            }else {
                                for(var index in result.errors){
                                    toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                }
                            }
                        });
                        break;
                    case 4:
                        CaseAnalysisService.putSearchParams({
                            search: $scope.condition.search
                        });
                        CaseAnalysisService.getCombinationCase().$promise.then(function (result) {
                            if("success" == result.status){
                                $scope.model = result.data;
                            }else {
                                for(var index in result.errors){
                                    toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                                }
                            }
                        });
                        break;
                }
            };

            // 获取案例内容
            CaseAnalysisService.getProcessCase().$promise.then(function (result) {
                if("success" == result.status){
                    $scope.model = result.data;
                }else {
                    for(var index in result.errors){
                        toastr.error(result.errors[index].errmsg,"数据信息获取失败");
                    }
                }
            });

            // 右侧案例内容的显示与隐藏
            $scope.num = $stateParams.num;
            $scope.isClicked1 = false;
            $scope.isClicked2 = false;
            $scope.isClicked3 = false;
            $scope.show=function(num){
                switch(num){
                    case 0:
                        $scope.isClicked1 = !$scope.isClicked1;
                        break;
                    case 1:
                        $scope.isClicked2 = !$scope.isClicked2;
                        break;
                    case 2:
                        $scope.isClicked3 = !$scope.isClicked3;
                        break;
                }
            }

            // 配置
            $scope.deploy = function () {
                $state.go('deployManagement');
            };
        }
    ]
);